package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.core.code.cmd.RbacCmdCode;
import com.ymk.bo.rbac.RbacRoleBO;
import com.ymk.service.IRbacRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class RbacRoleListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacRoleBO rbacRoleBO = super.getData(sign, RbacRoleBO.class);
        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("name", rbacRoleBO.getName())
                .addParam("status",rbacRoleBO.getStatus())
                .addParam("mchId",rbacRoleBO.getMchId())
                .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<RbacRoleBO> rbacRoleBOS = this.rbacRoleService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(rbacRoleBOS));
        return respSign;
    }

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacRoleBO rbacRoleBO = super.getData(sign, RbacRoleBO.class);
        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId", rbacRoleBO.getMchId())
                .addParam("status",rbacRoleBO.getStatus())
                .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<RbacRoleBO> rbacRoleBOS = this.rbacRoleService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(rbacRoleBOS));
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return RbacCmdCode.RBAC_ROLE_LIST;
    }

    @Autowired
    private IRbacRoleService rbacRoleService;
}
